<template>
	<z-paging ref="paging" v-model="list" @query="getList" loading-more-no-more-text='No more'>
		
		<view class="search">
			<uni-search-bar v-model="keyword" placeholder="Search Giftcards" @confirm="search" @cancel="search"
				cancel-text="search">
				<image slot="searchIcon" class="searchIcon" src="@/static/image/search.png" mode=""></image>
			</uni-search-bar>
		</view>
		<view class="section">
			<view class="title">
				All Gift Cards
			</view>
			<view class="tab">
				<text @click="active=0" :class="{active:active==0}">Featured</text>
				<text class="line">|</text>
				<text @click="active=1" :class="{active:active==1}">High to Low</text>
			</view>
		</view>
		<view class="list">
			<view class="col" v-for="item in list">
				<navigator :url="`./add?id=${item.id}`">
					<view class="item">
						<view class="title ovh">
							{{item.card_title}}
						</view>
						<image :src="item.image" mode=""></image>
						<view class="bottom">
							<view class="">
								<text>UP TO</text> # {{item.currency_unit}}{{item.amount}}
							</view>
							<image src="@/static/image/more.png" mode=""></image>
						</view>
					</view>
				</navigator>
			</view>
		</view>
	</z-paging>
</template>

<script>
	export default {
		data() {
			return {
				keyword: '',
				active: 0,
				list: []
			}
		},
		methods: {
			search() {
				this.$refs.paging.reload()
			},
			getList(pageNo, pageSize) {
				//这里的pageNo和pageSize会自动计算好，直接传给服务器即可
				this.$post("/index/cards_list", {
					currency_id: uni.getStorageSync("currency_id"),
					page: pageNo,
					row: pageSize,
					keyword:this.keyword,
				}).then(res => {
					//请勿在网络请求回调中给dataList赋值！！只需要调用complete就可以了
					this.$refs.paging.complete(res.data.data);
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #F1F2F7;
	}

	.search {
		background-color: #fff;

		.searchIcon {
			width: 30rpx;
			height: 30rpx;
		}
	}

	.section {
		padding: 0 32rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding-top: 30rpx;

		.title {
			font-size: 32rpx;
		}

		.tab {
			color: #666;
			font-size: 24rpx;

			.active {
				color: $main-color;
			}

			.line {
				padding: 0 20rpx;
				color: #ccc;
			}
		}
	}

	.list {
		padding: 24rpx;
		display: flex;
		flex-wrap: wrap;

		.col {
			padding: 8rpx;
			width: 50%;

			.item {
				background-color: #fff;
				padding: 16rpx;

				.title {
					text-align: center;
					font-weight: bold;
					font-size: 26rpx;
				}

				image {
					width: 204rpx;
					height: 146rpx;
					display: block;
					margin: 16rpx auto;
				}

				.bottom {
					display: flex;
					align-items: center;
					justify-content: space-between;
					background-color: rgba($color: #3959FA, $alpha: 0.05);
					border-radius: 8rpx;
					padding: 6rpx 10rpx;
					font-size: 24rpx;

					text {
						color: #999;
						margin-right: 10rpx;
					}

					image {
						width: 11rpx;
						height: 20rpx;
						margin: 0;
					}
				}
			}
		}
	}
</style>